package zouran.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zouran.entity.economicloss.Basestructure;
import zouran.entity.economicloss.Paralevel;
import zouran.entity.economicloss.Resetprice;
import zouran.entity.economicloss.Structure;
import zouran.entity.intentityimg.Eclipeser;
import zouran.mapper.EconomiclossMapper;
import zouran.service.EconomiclossService;

import java.util.*;


@Service
public class EconomiclossServiceImpl implements EconomiclossService {

    @Autowired
    private EconomiclossMapper economiclossMapper;

    @Override
    public List<Structure> getListall() {
        return economiclossMapper.getlistall();
    }

    @Override
    public Resetprice getPriceBycity(String city) {
        return economiclossMapper.getPriceBycity(city);
    }


    @Override
    public List<Basestructure> getbaseAll() {
        return economiclossMapper.getbaseAll();
    }

    @Override
    public List<Double> geteclipser(Eclipeser eclipeser) {
        List<Double> paraForml = eclipeser.getParaForml();
        List<Double> paraFormr = eclipeser.getParaFormr();
        double r1a,r1b,r2a,r2b,r3a,r3b;
        r1a = Math.exp((eclipeser.getIa()-0.18 - paraForml.get(0) - eclipeser.getMPara()*paraForml.get(1)) / paraForml.get(2)) - paraForml.get(3);
        r2a = Math.exp((eclipeser.getIa()-1 - paraForml.get(0) - eclipeser.getMPara()*paraForml.get(1)) / paraForml.get(2)) - paraForml.get(3);
        r3a = Math.exp((eclipeser.getIa()-1.8 - paraForml.get(0) - eclipeser.getMPara()*paraForml.get(1)) / paraForml.get(2)) - paraForml.get(3);
        r1b = Math.exp((eclipeser.getIa()+0.33 - paraFormr.get(0) - eclipeser.getMPara()*paraFormr.get(1)) / paraFormr.get(2)) - paraFormr.get(3);
        r2b = Math.exp((eclipeser.getIa()-0.7 - paraFormr.get(0) - eclipeser.getMPara()*paraFormr.get(1)) / paraFormr.get(2)) - paraFormr.get(3);
        r3b = Math.exp((eclipeser.getIa()-1.6 - paraFormr.get(0) - eclipeser.getMPara()*paraFormr.get(1)) / paraFormr.get(2)) - paraFormr.get(3);
        List<Double> rlist = new ArrayList<>();
        rlist.add(r1a);
        rlist.add(r1b);
        rlist.add(r2a);
        rlist.add(r2b);
        rlist.add(r3a);
        rlist.add(r3b);
        System.out.println(rlist);
        return rlist;
    }

    @Override
    public Map<String, Float> getnewfun(Map<String, Object> request) {
        List<String> labelList = (List<String>) request.get("labelList");
        Map<String, Float> map = new HashMap<>();
        Iterator<String> iterator = labelList.iterator();
        while (iterator.hasNext()) {
            String label = iterator.next();
            float temp = economiclossMapper.getparan1(label);
            map.put(label, temp);
        }
        return map;
    }

    @Override
    public Map<String, Paralevel> getnewfun1(Map<String, Object> request) {
        Map<String, Paralevel> map = new HashMap<>();
        List<String> labelList = (List<String>) request.get("labelList");
        int index = (Integer) request.get("index");
        Iterator<String> iterator = labelList.iterator();
        while (iterator.hasNext()) {
            String label = iterator.next();
            Paralevel Djs;
            if (index == 1){
                Djs = economiclossMapper.getParaDjs(label);
            }else if(index == 2){
                Djs = economiclossMapper.getParaDjd(label);
            }else if (index == 3){
                Djs = economiclossMapper.getParaDjc(label);
            }else {
                Djs = null;
            }
            map.put(label, Djs);
        }
        return map;
    }
}
